<template>
    <van-list v-model="loading" :finished="finished" :loading-text="$t('Loading')" :finished-text="$t('noMore')" offset='50' :error.sync="error" :error-text="$t('errorAndReload')" @load="onLoad">
        <div class="cart-box" v-for='item of dataList' :key='item.id'>
            <div class="head-box">{{item.deviceSN}}
                <div class="icon_pos" v-if="item.enableFlag==1&&item.authorizeFlag==1">
                    <van-icon name="setting-o" @click="goSetting(item.inverterType,item.deviceSN,item.wifiSN,item.transportType)" />
                </div>
            </div>
            <div class="titRow">{{$t('RegistrationNo')}} : {{item.wifiSN}}</div>
            <div class="titRow">{{$t('TodayYield')}} : {{item.todayYield | numFilter(1,'kWh')}}</div>
            <div class="titRow">{{$t('TotalYield')}} : {{item.totalYield | numFilter(1,'kWh')}}</div>
            <div class="titRow">{{$t('RatedPower')}} : {{item.ratedPower | numFilter(1,'kW')}}</div>
            <div class="titRow">{{$t('SiteName')}} : {{item.siteName}}</div>
            <div class="titRow">{{$t('Username')}} : {{item.userName | ifNull}}</div>
        </div>
    </van-list>
</template>

<script>
import moment from 'moment'
export default {
    props: {
        search:{
            type:String
        }
    },
    data() {
        return {
            dataList:[],
            loading:false,
            finished:false,
            current:1,
            error:false
        };
    },
    methods: {
        replay(val){
            this.current = 1
            this.dataList = []
            this.getAgentPage(val)
        },
        goSetting(inverterType,sn,wifiSN,transportType){
            localStorage.setItem("sn",sn);
            localStorage.setItem('wifiSN',wifiSN);
            localStorage.setItem('inverterType',inverterType);
            localStorage.setItem('transportType',transportType);
            sessionStorage.setItem('setFrom','/agentHome/inverter');
            if(inverterType==14){
                this.$router.push({path:'/x3hybridg4set'});
            }else if(inverterType==15){
                this.$router.push({path:'/x1hybridg4set'});
            }else{
                this.$router.push({path:'/setting'});
            }
        },
        async getAgentPage(val){
            this.comm.loadingShow();
            let {result:res} = await this.API.getDevWifiPage(localStorage.getItem("domain"),{
                tokenId:localStorage.getItem("tokenId"),
                current:this.current,
                size: 10,
                wifiSN:val,
                updateTime:moment(new Date()).format('YYYY-MM-DD')
            });
            this.dataList = [...this.dataList,...res.rows];
            this.loading = false;
            if((this.current-1)*10 > res.total){
                this.finished = true;
            }else{
                this.finished = false;
            }
            this.current++;
        },
        onLoad(){
            this.getAgentPage(this.search).catch(()=>{
                this.loading = false;
                this.error=true;
            });
        }
    },
};
</script>

<style  lang="less" scoped>
.cart-box{
    padding: 10px;
    background-color: #fff;
    margin-top: 15px;
    text-align: left;
    .head-box{
        border-bottom: 1px solid #e6e6e6;
        font-weight: 900;
        overflow: hidden;
        padding: 0 0 2px 0;
        .icon_pos{
            float: right;
            font-size: 24px;
        }
    }
    .titRow{
        width: 100%;
        margin-top: 6px;
        font-size: 15px;
    }
}
</style>
